import { tokenName } from "@/server/base.js";
const getUserInfo = function () {
  try {
    const userString = localStorage.getItem(tokenName);
    return JSON.parse(userString);
  } catch (e) {
    return {}
  }
}

const state = {
  userName: '',
  userInfo: {}
}

const mutations = {
  userInfo(state, userInfo) {
    localStorage.setItem(tokenName, JSON.stringify(userInfo));
  }
}
export default {
  namespaced: true,
  state,
  getters: {
    userName(state) {
      try {
        state.userName = getUserInfo().username;
      } catch (e) {
        state.userName = "";
      }
      return state.userName;
    },
    userInfo(state) {
      return state.userInfo = getUserInfo();
    }
  },
  mutations,
  actions: {}
}
